export function cancelTimeout(id: number) {
  cancelAnimationFrame(id)
}

export function requestTimeout(callback: () => void, delay: number) {
  const start = Date.now()
  let id: number
  function tick() {
    if (Date.now() - start >= delay) {
      callback.call(null)
    } else {
      id = requestAnimationFrame(tick)
    }
  }
  id = requestAnimationFrame(tick)
  return id
}
